package com.easepal802s.project.ui.fragment;

import android.graphics.Color;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.appcompat.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;


import com.easepal802s.project.R;
import com.easepal802s.project.view.loopview.LoopView;
import com.easepal802s.project.view.loopview.OnItemSelectedListener;

import java.util.ArrayList;

/**
 * Created by FHB on 2018/3/28.
 */

public class BaseTimeTaskFragment extends Fragment {

    private onDataListener listener;

    @Override
    public void onCreate( Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    public void showDialog() {
        AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity());
        LayoutInflater inflater = getActivity().getLayoutInflater();
        View dialogView = inflater.inflate(R.layout.dialog_loopview, null);
        dialogBuilder.setView(dialogView);

        LoopView loopView = (LoopView) dialogView.findViewById(R.id.loopView);
        final ArrayList<String> list = new ArrayList<>();
        list.add("5 : 00" );
        list.add("10 : 00" );
        list.add("15 : 00" );
        list.add("20 : 00" );
        list.add("25 : 00" );
        //  滚动监听
        loopView.setListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(int index) {
                String data = list.get(index);
                if(listener != null){
                    listener.OnDataListener(data);
                }
            }
        });
        // 设置原始数据
        loopView.setItems(list);
        loopView.setCurrentPosition(2);
        loopView.setItemsVisibleCount(5);
        loopView.setDividerColor(getResources().getColor(R.color.white));
        loopView.setOuterTextColor(Color.GRAY);
        loopView.setCenterTextColor(Color.CYAN);
        AlertDialog alertDialog = dialogBuilder.create();
        alertDialog.show();
    }

    public interface   onDataListener{
           void OnDataListener(String msg);
    }

    public void setTimeListener( onDataListener listener){
        this.listener = listener;
    }
}
